package com.zbkj.admin.controller.brand;

import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.*;
import com.zbkj.common.response.MerchantBrokerageDetailResponse;
import com.zbkj.common.response.MerchantBrokeragePageDataResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.CommunityBrokerageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 商户分红管理 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/brand/merchant/brokerage")
@Api(tags = "商户分红管理") //配合swagger使用

public class BrandMerchantBrokerageController {

    @Autowired
    private CommunityBrokerageService communityBrokerageService;

    /**
     * 分页显示小区分佣设置表
     *
     * @param request          搜索条件
     * @param pageParamRequest 分页参数
     * @author Caiyc
     * @since 2025-07-21
     */
//    @PreAuthorize("hasAuthority('platform:activitystyle:list')")
    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/page/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<MerchantBrokeragePageDataResponse>> getList(@Validated MerchantBrokerageSearchRequest request,
                                                                               @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<MerchantBrokeragePageDataResponse> communityBrokerageCommonPage = CommonPage.restPage(communityBrokerageService.getList(request, pageParamRequest));
        return CommonResult.success(communityBrokerageCommonPage);
    }

    /**
     * 修改小区分佣设置表
     * @param communityBrokerageRequest 修改参数
     * @author Caiyc
     * @author Caiyc
     * @since 2025-07-21
     */
    @ApiOperation(value = "新增或修改")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<String> save(@RequestBody @Validated MerchantBrokerageSaveRequest communityBrokerageRequest) {
        if (communityBrokerageService.updateByMerchant(communityBrokerageRequest)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 查询小区分佣设置表详情
     * @param id 主键ID
     * @author Caiyc
     * @since 2025-07-21
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    public CommonResult<MerchantBrokerageDetailResponse> getDetails(@PathVariable("id") Integer id) {
        return CommonResult.success(communityBrokerageService.getDetailsByMerchant(id));
    }

    @LogControllerAnnotation(intoDB = true, methodType = MethodType.DELETE, description = "批量删除商户分红")
    @ApiOperation(value = "批量删除")
    @RequestMapping(value = "/batch/delete", method = RequestMethod.POST)
    public CommonResult<String> batchDelete(@RequestBody @Validated CommonBatchRequest request) {
        if (communityBrokerageService.batchDelete(request.getIdList())) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

}



